Skip to content

Fix swapped Hi L1B hae_latitude/hae_longitude and return longitude in [0, 360) from instrument_pointing - #3604

Merged
tmplummer merged 3 commits into
IMAP-Science-Operations-Center:devfrom
tmplummer:3603-hi-l1b-lat-lon-swap
Nov 4, 2026
Merged

tmplummer merged 3 commits into
IMAP-Science-Operations-Center:devfrom
tmplummer:3603-hi-l1b-lat-lon-swap

Conversation

@tmplummer

@tmplummer tmplummer commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Change Summary

Overview

  • Fixes Hi L1B DE: hae_latitude and hae_longitude are swapped #3603: Hi L1B DE hae_latitude and hae_longitude were swapped because instrument_pointing() returns (longitude, latitude).
  • instrument_pointing() now returns longitude in [0, 360), matching IDEX and the L1C PSET. Hi L1B is the only production caller that uses the (lon, lat) output; IDEX and Lo use cartesian=True. I decided to change the output of this function based on research indicating that in the heliophysics community, it is an agreed upon standard to report ecliptic longitude in the range: [0, 360)

File changes

  • imap_processing/spice/geometry.py: instrument_pointing() uses cartesian_to_spherical() in place of the per-vector spiceypy.reclat loop; docstring documents output ranges.
  • imap_processing/hi/hi_l1b.py: compute_hae_coordinates() assigns column 0 to longitude and column 1 to latitude.
  • imap_processing/tests/spice/test_geometry.py: new test_instrument_pointing_lon_lat mocks frame_transform with known cartesian vectors (all quadrants, poles, single and multiple inputs) and checks exact lon/lat values and the [0, 360) range.
  • imap_processing/tests/hi/test_hi_l1b.py: test_compute_hae_coordinates uses distinct lat/lon values so a swap is caught.

Testing

  • 123 tests pass in test_hi_l1b.py and test_geometry.py; 321 pass across Hi L1B, geometry, IDEX, and Lo L1B.
  • Both new/updated tests fail without the corresponding code fix.

tmplummer and others added 2 commits October 28, 2026 14:57
instrument_pointing returns (longitude, latitude), but compute_hae_coordinates
assigned column 0 to latitude. Also wrap longitude into [0, 360) to match
the CDF attributes and L1C PSET convention.

Closes IMAP-Science-Operations-Center#3603

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the per-vector spiceypy.reclat loop with cartesian_to_spherical so
(lon, lat) output uses the same [0, 360) longitude convention as IDEX and
the Hi L1C PSET. Drop the now-redundant wrap in Hi L1B and add a mocked
frame_transform test with known cartesian vectors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmplummer tmplummer changed the title Fix swapped hae_latitude/hae_longitude in Hi L1B DE Fix swapped Hi L1B hae_latitude/hae_longitude and return longitude in [0, 360) from instrument_pointing Oct 28, 2026
if isinstance(et, typing.Collection):
return np.rad2deg([spiceypy.reclat(vec)[1:] for vec in pointing])
return np.rad2deg(spiceypy.reclat(pointing)[1:])
return cartesian_to_spherical(pointing, degrees=True)[..., 1:3]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change to instrument_pointing when cartesian=False. Searching the repo, the only usage with cartesian=False was in the hi_l1b.py module. Two other uses of instrument_pointing all pass cartesian=True:

@lacoak21

Copy link
Copy Markdown
Contributor

LGTM!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review identifies no active issues and documents targeted fixes with regression coverage for coordinate ordering, normalization, quadrants, poles, and vector shapes.

No open issues 🎉

What changed in this PR

This pull request fixes swapped Hi L1B HAE latitude/longitude assignments and standardizes non-Cartesian instrument_pointing() output to return longitude in [0, 360) with latitude in [-90, 90].

Changes:

  • Uses cartesian_to_spherical() for normalized longitude handling.
  • Corrects Hi L1B longitude and latitude assignments.
  • Adds regression coverage for coordinate ordering, wrapping, quadrants, poles, and vector shapes.
File Description
imap_processing/​tests/​spice/​test_geometry.py Tests longitude/latitude values, [0, 360) normalization, vector shapes, quadrants, and poles.
imap_processing/​tests/​hi/​test_hi_l1b.py Uses distinct mocked coordinates to detect swapped assignments.
imap_processing/​spice/​geometry.py Updates instrument_pointing() conversion and documents output ranges and shapes.
imap_processing/​hi/​hi_l1b.py Assigns longitude and latitude from the correct pointing columns.

Review effort: Lite

@leowerneck leowerneck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I made a minor comment

Comment thread imap_processing/spice/geometry.py Outdated
By default, the coordinates returned are (Longitude, Latitude) coordinates in
the reference frame `to_frame`. Cartesian coordinates can be returned if
desired by setting `cartesian=True`.
By default, the coordinates returned are (Longitude, Latitude) coordinates, in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a redundant "coordinates" in the first line; could drop the second one.

Comment thread imap_processing/spice/geometry.py Resolved
@tmplummer
tmplummer merged commit 2bc1d49 into IMAP-Science-Operations-Center:dev Nov 4, 2026
22 checks passed
@tmplummer
tmplummer deleted the 3603-hi-l1b-lat-lon-swap branch November 4, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hi L1B DE: hae_latitude and hae_longitude are swapped

4 participants